﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using blackhouse.Data;
using System.Data;

namespace blackhouse.BlackApart.Data.Sql {
    public class ApartmentLocationDataAccess : AdoApartmentLocationDataAccess {

        #region Fields

        private string connectionString;
        private MsSqlAdoDataHelper dataHelper;

        #endregion

        #region Constructors

        public ApartmentLocationDataAccess(string sqlConnectionString) {
            this.connectionString = sqlConnectionString;
            this.dataHelper = new MsSqlAdoDataHelper(this.connectionString);
            SqlVersioning versioning = new SqlVersioning(this.connectionString, this.GetType().Assembly);
        }

        #endregion

        #region AdoApartmentLocationDataAccess Members

        protected override System.Data.IDataReader GetReaderForApartmentLocation(int locationId) {
            this.dataHelper.Reset();
            this.dataHelper.ProcedureName = "bhp_ApartmentLocationGet";
            this.dataHelper.AddParameter("Id", locationId);
            IDataReader reader = this.dataHelper.Execute();
            return reader;
        }

        public override int Save(int id, double latitude, double longitude, string locationName) {
            this.dataHelper.Reset();
            this.dataHelper.ProcedureName = "bhp_ApartmentLocationSave";
            this.dataHelper.AddParameter("Id", id, System.Data.DbType.Int32);
            this.dataHelper.AddParameter("Name", locationName);
            this.dataHelper.AddParameter("Latitude", latitude, System.Data.DbType.Double);
            this.dataHelper.AddParameter("Longitude", latitude, System.Data.DbType.Double);
            return Convert.ToInt32(this.dataHelper.ExecuteScalar());
        }

        #endregion

    }
}
